package cc.eddic.practice.concurrency.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;


public class Test {
    public static void compressFile(String sourceFile,String destinationFolder) throws IOException {
        File folder=new File(destinationFolder);
        if(!folder.exists()){
            folder.mkdir();
        }
        FileInputStream fis=new FileInputStream(sourceFile);
        GZIPInputStream gzipIS=new GZIPInputStream(fis);
        String originalFileName = sourceFile.substring(0, sourceFile.lastIndexOf(".gz"));
        String filePath=destinationFolder+File.separator+originalFileName;
        FileOutputStream fos=new FileOutputStream(filePath);

        byte [] buffer=new byte[1024*8];

        int len;
        while((len=gzipIS.read(buffer))>0){
            fos.write(buffer,0,len);
        }

        gzipIS.close();
        fos.close();
        fis.close();
    }

    public static void main(String[] args)  {
        String sourceFile="D:\\io\\cdn-pri.htn.gegee.cc_2023-04-01-01_part-00000.gz";
        String destinationFolder="";

        try {
            compressFile(sourceFile,destinationFolder);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
